<!DOCTYPE html><html lang="[&quot;zh-Hans&quot;,&quot;zh-CN&quot;,&quot;default&quot;]"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta name="description" content="响应式开发-1"><meta name="keywords" content="css,响应式"><meta name="author" content="wenmu"><meta name="copyright" content="wenmu"><title>响应式开发-1 | 温木的博客</title><link rel="shortcut icon" href="/melody-favicon.ico"><link rel="stylesheet" href="/css/index.css?version=1.6.1"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css?version=1.6.1"><link rel="dns-prefetch" href="https://cdn.staticfile.org"><link rel="dns-prefetch" href="https://cdn.bootcss.com"><link rel="dns-prefetch" href="https://creativecommons.org"><link rel="dns-prefetch" href="http://ta.qq.com"><script>(function() {
   var hm = document.createElement("script");
   hm.src = "https://tajs.qq.com/stats?sId=&lt;script type=&quot;text/javascript&quot; src=&quot;http://tajs.qq.com/stats?sId=66523541&quot; charset=&quot;UTF-8&quot;&gt;&lt;/script&gt;";
   var s = document.getElementsByTagName("script")[0];
   s.parentNode.insertBefore(hm, s);
 })();</script><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  }
} </script><meta name="generator" content="Hexo 4.2.0"></head><body><i class="fa fa-arrow-right" id="toggle-sidebar" aria-hidden="true"></i><div id="sidebar"><div class="toggle-sidebar-info text-center"><span data-toggle="切换文章详情">切换站点概览</span><hr></div><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar"></div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#概况"><span class="toc-number">1.</span> <span class="toc-text">概况</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#响应式网站概念"><span class="toc-number">1.1.</span> <span class="toc-text">响应式网站概念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#响应式网站的有点"><span class="toc-number">1.2.</span> <span class="toc-text">响应式网站的有点</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#响应式网站的缺点"><span class="toc-number">1.3.</span> <span class="toc-text">响应式网站的缺点</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看浏览器时长份额"><span class="toc-number">1.4.</span> <span class="toc-text">查看浏览器时长份额</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css3-媒体属性简介"><span class="toc-number">1.5.</span> <span class="toc-text">css3 媒体属性简介</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#视口宽度和设备宽度的区别"><span class="toc-number">1.5.1.</span> <span class="toc-text">视口宽度和设备宽度的区别</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#为什么会有三个视口呢？"><span class="toc-number">1.5.2.</span> <span class="toc-text">为什么会有三个视口呢？</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#响应式网站设计实践原则"><span class="toc-number">1.6.</span> <span class="toc-text">响应式网站设计实践原则</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#如何组织项目目录结构"><span class="toc-number">1.7.</span> <span class="toc-text">如何组织项目目录结构</span></a></li></ol></li></ol></div></div><div class="author-info hide"><div class="author-info__avatar text-center"><img src="https://i.loli.net/2020/02/27/xwaBoOj158MfNyq.jpg"></div><div class="author-info__name text-center">wenmu</div><div class="author-info__description text-center">记录一些在工作中或学习新知识时学到的一些知识点；正所谓好记性不如一个烂笔头，温故而知新！</div><hr><div class="author-info-articles"><a class="author-info-articles__archives article-meta" href="/archives"><span class="pull-left">文章</span><span class="pull-right">115</span></a><a class="author-info-articles__tags article-meta" href="/tags"><span class="pull-left">标签</span><span class="pull-right">52</span></a><a class="author-info-articles__categories article-meta" href="/categories"><span class="pull-left">分类</span><span class="pull-right">30</span></a></div></div></div><div id="content-outer"><div class="no-bg" id="top-container"><div id="page-header"><span class="pull-left"> <a id="site-name" href="/">温木的博客</a></span><i class="fa fa-bars toggle-menu pull-right" aria-hidden="true"></i><span class="pull-right menus"><a class="site-page" href="/">首页</a><a class="site-page" href="/archives">文章</a><a class="site-page" href="/tags">标签</a><a class="site-page" href="/categories">分类</a></span></div><div id="post-info"><div id="post-title">响应式开发-1</div><div id="post-meta"><time class="post-meta__date"><i class="fa fa-calendar" aria-hidden="true"></i> 2020-02-25</time><span class="post-meta__separator">|</span><i class="fa fa-inbox post-meta__icon" aria-hidden="true"></i><a class="post-meta__categories" href="/categories/%E5%93%8D%E5%BA%94%E5%BC%8F/">响应式</a></div></div></div><div class="layout" id="content-inner"><article id="post"><div class="article-container" id="post-content"><h1 id="概况"><a href="#概况" class="headerlink" title="概况"></a>概况</h1><p>记录在学习响应式布局时学到的只是点。</p>
<h2 id="响应式网站概念"><a href="#响应式网站概念" class="headerlink" title="响应式网站概念"></a>响应式网站概念</h2><ul>
<li>flexible grid layout 弹性网格布局</li>
<li>flexible image 弹性图片</li>
<li>media queries 媒体查询</li>
</ul>
<blockquote>
<p>响应式网站是一个设计理念，它是多项技术的综合体。</p>
</blockquote>
<p>在使用弹性盒子 flex 布局时，会有他的局限性，虽然会弹性伸缩，但是样式不能保证。</p>
<a id="more"></a>

<h2 id="响应式网站的有点"><a href="#响应式网站的有点" class="headerlink" title="响应式网站的有点"></a>响应式网站的有点</h2><ul>
<li>减少工作量<ol>
<li>网站、设计、代码、内容都只需要一份</li>
<li>多出来的工作量只是 JS 脚本、CSS 样式做一些改动</li>
</ol>
</li>
<li>节省时间<ol>
<li>迅速发布、快速迭代、敢于试错、小步快跑</li>
</ol>
</li>
<li>跨终端<br>每个设备都你能得到正确的设计，面向未来 -搜索优化<br>不需要为不同的终端申请不同的域名，共用一个网址</li>
</ul>
<h2 id="响应式网站的缺点"><a href="#响应式网站的缺点" class="headerlink" title="响应式网站的缺点"></a>响应式网站的缺点</h2><ol>
<li>会加载更多的样式和脚本资源</li>
<li>设计比较难精准定位和控制</li>
<li>老版本浏览兼容不好</li>
</ol>
<h2 id="查看浏览器时长份额"><a href="#查看浏览器时长份额" class="headerlink" title="查看浏览器时长份额"></a>查看浏览器时长份额</h2><ol>
<li><a href="https://www.caniuse.com/" target="_blank" rel="noopener">caniuse</a><br>这个统计的全世界的</li>
<li><a href="https://gs.statcounter.com/" target="_blank" rel="noopener">https://gs.statcounter.com/</a><br>这个可以选择区域</li>
</ol>
<h2 id="css3-媒体属性简介"><a href="#css3-媒体属性简介" class="headerlink" title="css3 媒体属性简介"></a>css3 媒体属性简介</h2><ul>
<li>width:视口宽度</li>
<li>height:视口高度</li>
<li>device-width:渲染表面的宽度，就是设备屏幕的宽度</li>
<li>device-height:渲染表面的高度，就是设备屏幕的高度</li>
<li>orientation:检查设备是处于横向还是纵向</li>
<li>aspect-radio:基于视口宽度和高度的宽高比<br>比如 width/height 16/9 或者 4/3</li>
<li>color:每种颜色的位数 bits，如 min-color:16 位、8 位</li>
<li>resolution:检测屏幕或打印机的分辨率<br>如：min-resolution:300dpi</li>
</ul>
<p>以上属性都可以添加<code>min-</code>和<code>max-</code>前缀</p>
<h3 id="视口宽度和设备宽度的区别"><a href="#视口宽度和设备宽度的区别" class="headerlink" title="视口宽度和设备宽度的区别"></a>视口宽度和设备宽度的区别</h3><p>在传统 PC 上，桌面浏览器的视口(viewport)就是浏览器主窗口的区域。但在手机端，浏览器的有三个视口的概念</p>
<ol>
<li>布局视口(layout viewport)</li>
<li>可视视口(visual viewport)</li>
<li>理想视口(ideal viewport)</li>
</ol>
<h3 id="为什么会有三个视口呢？"><a href="#为什么会有三个视口呢？" class="headerlink" title="为什么会有三个视口呢？"></a>为什么会有三个视口呢？</h3><p>因为浏览器原先是为 PC 设计的，最小宽度也是 960 像素，当移动端出来后，当时 iPhone 的屏幕宽度才 320px，移动端显示这些页面，很不友好，体验较差；这时乔帮主就引入一个布局视口的概念，这个视口先不在手机上显示，用一个虚拟的布局视口把网页显示出来，一般把这个布局视口宽度设置成 960px；然后通过缩放布局视口，比如 0.3 倍，就可以在可视视口查看网页内容。可以放大、滑动来查看网页的不同部分内容。放大和滑动的都是布局视口。</p>
<p><img src="https://i.loli.net/2020/02/27/Io14W7J3gwVKs6H.png" alt="image.png"></p>
<ul>
<li>黑色阴影部分就是布局视口，它的宽度一直是 960px，</li>
<li>看到内容的地方就是可视视口</li>
</ul>
<p><strong>理想视口</strong>就是布局视口在一个设备上的最佳尺寸。理想视口下的页面便于浏览器浏览、阅读。不需要缩放就可以很方便浏览页面。</p>
<p>###设置理想视口</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;meda name&#x3D;&quot;viewport&quot; content&#x3D;&quot;width&#x3D;device-width&quot; &#x2F;&gt;</span><br></pre></td></tr></table></figure>

<p>布局视口的宽度和设备可视视口的宽度一致。这样在设计时，就根据设备的宽度进行设计即可。不要再进行缩放来显示内容。<br>很多网站直接禁止了缩放，比如百度</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;meda name&#x3D;&quot;viewport&quot; content&#x3D;&quot;width&#x3D;device-width,minimux-scale&#x3D;1.0,maximum-scale&#x3D;1.0,user-scalable&#x3D;no&quot; &#x2F;&gt;</span><br></pre></td></tr></table></figure>

<h2 id="响应式网站设计实践原则"><a href="#响应式网站设计实践原则" class="headerlink" title="响应式网站设计实践原则"></a>响应式网站设计实践原则</h2><ol>
<li>progressive enhancement 渐进增强<br>先构建一个简单的基本效果，然后根据不同的浏览器和分辨率的特点，逐渐增加新功能，比如增加个圆角、阴影、动画等等。</li>
<li>graceful degradation 优雅降级<br>这个正好相反，我们先构建一个最优雅最漂亮的效果，然后根据不同浏览器不支持的效果，去掉响应的效果。</li>
</ol>
<p>建议采用<strong>优雅降级</strong>方案。<br>先根据小屏进行设计还是大屏进行设计？<br>这个根据实际情况来确定。<br>确定要支持的浏览器范围。</p>
<h2 id="如何组织项目目录结构"><a href="#如何组织项目目录结构" class="headerlink" title="如何组织项目目录结构"></a>如何组织项目目录结构</h2><ul>
<li>约定优于配置</li>
<li>约定代码结构或命名规范来减少配置数量</li>
</ul>
</div></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">wenmu</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://blog.wangpengpeng.site/2020/02/25/%E5%93%8D%E5%BA%94%E5%BC%8F%E5%BC%80%E5%8F%91-1/">http://blog.wangpengpeng.site/2020/02/25/%E5%93%8D%E5%BA%94%E5%BC%8F%E5%BC%80%E5%8F%91-1/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://blog.wangpengpeng.site">温木的博客</a>！</span></div></div><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/css/">css</a><a class="post-meta__tags" href="/tags/%E5%93%8D%E5%BA%94%E5%BC%8F/">响应式</a></div><div class="post-qr-code"><div class="post-qr-code-item"><img class="post-qr-code__img" src="https://i.loli.net/2020/02/27/hOBzIxFDJMCrmtN.jpg"><div class="post-qr-code__desc">微信打赏</div></div></div><nav id="pagination"><div class="prev-post pull-left"><a href="/2020/02/28/%E4%B8%A4%E4%B8%AAmac%E4%B9%8B%E9%97%B4%E5%BF%AB%E9%80%9F%E4%BC%A0%E9%80%92%E6%96%87%E4%BB%B6/"><i class="fa fa-chevron-left">  </i><span>两个mac之间快速传递文件</span></a></div><div class="next-post pull-right"><a href="/2020/02/25/%E5%93%8D%E5%BA%94%E5%BC%8F%E5%BC%80%E5%8F%91/"><span>响应式开发</span><i class="fa fa-chevron-right"></i></a></div></nav><div id="vcomment"></div><script src="https://cdn1.lncld.net/static/js/3.0.4/av-min.js"></script><script src="https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js"></script><script>var notify = 'false' == true ? true : false;
var verify = 'false' == true ? true : false;
var GUEST_INFO = ['nick','mail','link'];
var guest_info = 'nick,mail,link'.split(',').filter(function(item){
  return GUEST_INFO.indexOf(item) > -1
});
guest_info = guest_info.length == 0 ? GUEST_INFO :guest_info;
window.valine = new Valine({
  el:'#vcomment',
  notify:notify,
  verify:verify,
  appId:'U1QqpeQNuBnRsfygHk1GQ30q-gzGzoHsz',
  appKey:'dunDQzEseDzgsKgw4qLQcog1',
  placeholder:'支持markdown！',
  avatar:'wavatar',
  guest_info:guest_info,
  pageSize:'20',
  lang: 'zh-cn'
})</script></div></div><footer><div class="layout" id="footer"><div class="copyright">&copy;2019 - 2020 By wenmu</div><div class="framework-info"><span>驱动 - </span><a href="http://hexo.io" target="_blank" rel="noopener"><span>Hexo</span></a><span class="footer-separator">|</span><span>主题 - </span><a href="https://github.com/Molunerfinn/hexo-theme-melody" target="_blank" rel="noopener"><span>Melody</span></a></div><div class="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_page_pv">该文访问量<span id="busuanzi_value_page_pv"></span><span></span></span></div></div></footer><i class="fa fa-arrow-up" id="go-up" aria-hidden="true"></i><script src="https://cdn.jsdelivr.net/npm/animejs@latest/anime.min.js"></script><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@latest/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-ui-pack@latest/velocity.ui.min.js"></script><script src="/js/utils.js?version=1.6.1"></script><script src="/js/fancybox.js?version=1.6.1"></script><script src="/js/sidebar.js?version=1.6.1"></script><script src="/js/copy.js?version=1.6.1"></script><script src="/js/fireworks.js?version=1.6.1"></script><script src="/js/transition.js?version=1.6.1"></script><script src="/js/scroll.js?version=1.6.1"></script><script src="/js/head.js?version=1.6.1"></script><script>if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
  $('#nav').addClass('is-mobile')
  $('footer').addClass('is-mobile')
}</script></body></html>